GDAS001-安装Bioconductor与获取帮助

安装Bioconductor

使用以下代码安装Bioconductor,直接粘贴到R的控制台即可。

1
2
source("http://bioconductor.org/biocLite.R")
biocLite()

这两行代码会安装核心的Bioconductor包。如果要再安装其它的包,则要使用biocLite()函数,并且使用字符串参数指定包的名称,例如我们安装以下的两个包:

1
biocLite(c("genefilter","geneplotter"))

在使用的时候,就跟常规的R包一样了,例如library()加载即可,例如 library(genefilter)

获取帮助

R中的帮助函数很多, 如果在命令行中直接输入 help.start() 就能查看R帮助起始页面。

查看函数帮助文档

通常情况,使用?后面添加函数名称,回车则可以查看此函数的帮助文档。使用example(函数)则能查看该函数的帮助文档中Examples部分中的案例,如下所示:

1
2
3
4
?mean
?mad
example(mad)
example(boxplot)

输入函数名称,但不添加任何参数,则显示此函数的所有代码。

在函数的帮助文档中,我们可以看到许多内容,包括关于此函数的描述,用法,参数,细节,参考文献,使用案例等。

包帮助

如果想查看某个包中所有函数的帮助文档,那么此时可以直接查看该函数的包文档,如果想使用Web浏览器来查看这些文档,那么需要添加以下参数(R默认的IDE):

1
help(package="genefilter", help_type="html")

如果使用的Rstudio,那么上述命令与下面命令的功能是一样的:

1
help(package="genefilter")

一种查看某个包中的有哪些函数的快速方法是使用双冒号::,如下所示:

1
2
library(geneplotter)
geneplotter::

对象帮助

如果要在R中查看某个对象的帮助信息,可以按如下操作:

1
2
3
class(6)
?numeric
?"numeric-class"

不过有的时候,在一些包中,某个构建的函数与此函数构建的对象的帮助文档是一样的,如下所示:

1
2
3
library(Biobase)
?ExpressionSet
?"ExpressionSet-class"

快速查看某个对象的方法:

1
2
methods(class="ExpressionSet")
methods(class="lm")

使用method()函数则能查看由某个类定义的实例的所有方法:

R has good capabilities for self-description. Classes can be formally linked to methods that operate usefully on their instances. The methods available can be listed using the methods function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
data(sample.ExpressionSet)
methods(class=class(sample.ExpressionSet))
## [1] [ [[ [[<- $$
## [5] $$<- abstract annotation annotation<-
## [9] as.data.frame assayData assayData<- classVersion
## [13] classVersion<- coerce combine description
## [17] description<- dim dimnames dimnames<-
## [21] dims esApply experimentData experimentData<-
## [25] exprs exprs<- fData fData<-
## [29] featureData featureData<- featureNames featureNames<-
## [33] fvarLabels fvarLabels<- fvarMetadata fvarMetadata<-
## [37] initialize isCurrent isVersioned KEGG2heatmap
## [41] KEGGmnplot makeDataPackage Makesense notes
## [45] notes<- pData pData<- phenoData
## [49] phenoData<- preproc preproc<- protocolData
## [53] protocolData<- pubMedIds pubMedIds<- rowMedians
## [57] rowQ sampleNames sampleNames<- show
## [61] storageMode storageMode<- updateObject updateObjectTo
## [65] varLabels varLabels<- varMetadata varMetadata<-
## [69] write.exprs
## see '?methods' for accessing help and source code

源代码

You can find the source code for many functions by typing out the name of the function without () and pressing enter.

1
2
3
4
5
6
7
read.csv
## function (file, header = TRUE, sep = ",", quote = "\\"", dec = ".",
## fill = TRUE, comment.char = "", ...)
## read.table(file = file, header = header, sep = sep, quote = quote,
## dec = dec, fill = fill, comment.char = comment.char, ...)
## <bytecode: 0x7f8e35b19200>
## <environment: namespace:utils>

我们从上面可以看出来,read.csv()函数只是打包了(wraps)了read.table()函数。

有的时候,你需要指定一个特定的类,才能查看该方法的源代码,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
plotMA
## nonstandardGenericFunction for "plotMA" defined from package "BiocGenerics"
##
## function (object, ...)
## {
## standardGeneric("plotMA")
## }
## <environment: 0x7f8e338381b8>
## Methods may be defined for arguments: object
## Use showMethods("plotMA") for currently available ones.
showMethods("plotMA")
## Function: plotMA (package BiocGenerics)
## object="ANY"
## object="data.frame"
getMethod("plotMA","data.frame")
## Method Definition:
##
## function (object, ...)
## {
## .local <- function (object, ylim = NULL, colNonSig = "gray32",
## colSig = "red3", colLine = "#ff000080", log = "x", cex = 0.45,
## xlab = "mean expression", ylab = "log fold change", ...)
## {
## if (!(ncol(object) == 3 & inherits(object[[1]], "numeric") &
## inherits(object[[2]], "numeric") & inherits(object[[3]],
## "logical"))) {
## stop("When called with a data.frame, plotMA expects the data frame to have 3 columns, two numeric ones for mean and log fold change, and a logical one for significance.")
## }
## colnames(object) <- c("mean", "lfc", "sig")
## object = subset(object, mean != 0)
## py = object$lfc
## if (is.null(ylim))
## ylim = c(-1, 1) * quantile(abs(py[is.finite(py)]),
## probs = 0.99) * 1.1
## plot(object$mean, pmax(ylim[1], pmin(ylim[2], py)), log = log,
## pch = ifelse(py < ylim[1], 6, ifelse(py > ylim[2],
## 2, 16)), cex = cex, col = ifelse(object$sig,
## colSig, colNonSig), xlab = xlab, ylab = ylab,
## ylim = ylim, ...)
## abline(h = 0, lwd = 4, col = colLine)
## }
## .local(object, ...)
## }
## <environment: namespace:geneplotter>
##
## Signatures:
## object
## target "data.frame"
## defined "data.frame"

简要案例Vignettes

“Vignettes”包含在R包中,并且是Bioconductor包的标准组件之一。这个函数通常会通过“块”代码的形式,来显示此包中函数的使用案例。

在Bioconductor的官网有PDF格式或R代码的Vignettes。此外,通过在R中来调用vignette能够保证正在使用的包的正确版本。以下代码就是列出某个特定包的vignettes名字,如下所示:

1
vignette(package="Biobase")

结果如下所示:

1
2
3
4
5
6
7
8
9
Vignettes in package ‘Biobase’:
ExpressionSetIntroduction
An introduction to Biobase and
ExpressionSets (source, pdf)
esApply esApply Introduction (source, pdf)
BiobaseDevelopment
Notes for eSet developers (source,
pdf)

进行一步调用 vignette 能够浏览PDF格式的内容:

1
vignette("ExpressionSetIntroduction")

也可以使用Web浏览器的方式来查看vignette,如下所示:

1
browseVignettes(package="Biobase")

分析帮助

workflows repository 这个库中包含了大量的可计算文档(computable documents),以及描述了如何执行某些常见的分析,这些数据来源于已经发布的数据。

总结

  • Bioconductor上的所有R函数都有自己的文档,以及运行案例;
  • 所有的Bioconductor包都有自己的vignettes,它描述了该包中的函数如何配合使用,并且是如何实现包的目标;
  • Bioconductor包含许多workflow documents,我们可以通过这些工作流程文档来进行学习;
  • R内置了许多基础函数用于完成基础的统计分析;
  • R’s mailing list for elementary questions 与Bioconductor’s support site 上含有非常多的信息,可以用于进一步的学习。

参考资料

  1. Installing Bioconductor and finding help